﻿#pragma once

namespace RoboCupStrategy {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Form1 的摘要
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: 在此加入建構函式程式碼
			//
			iniGlobVariable();
		}

	protected:
		/// <summary>
		/// 清除任何使用中的資源。
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}

	protected: 



	private: System::Windows::Forms::Timer^  timer1;
	private: System::ComponentModel::IContainer^  components;
	private: System::Windows::Forms::GroupBox^  groupBox1;
	private: System::Windows::Forms::PictureBox^  Camera;
	private: System::Windows::Forms::MenuStrip^  menuStrip1;
	private: System::Windows::Forms::ToolStripMenuItem^  aToolStripMenuItem1;
	private: System::Windows::Forms::ToolStripMenuItem^  realToolStripMenuItem;
	private: System::Windows::Forms::TrackBar^  HeadBar_V;
	private: System::Windows::Forms::TrackBar^  HeadBar_H;
	private: System::Windows::Forms::GroupBox^  groupBox2;
	private: System::Windows::Forms::Button^  MotionSendBtn;
	private: System::Windows::Forms::TextBox^  MotionSendText;




	private: System::Windows::Forms::ToolStripMenuItem^  simulationToolStripMenuItem;
	protected: 

	private:
		/// <summary>
		/// 設計工具所需的變數。
		/// </summary>
		//System::Drawing::Bitmap^ bmp;


#pragma region Windows Form Designer generated code
		/// <summary>
		/// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器
		/// 修改這個方法的內容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->HeadBar_V = (gcnew System::Windows::Forms::TrackBar());
			this->HeadBar_H = (gcnew System::Windows::Forms::TrackBar());
			this->Camera = (gcnew System::Windows::Forms::PictureBox());
			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->aToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->realToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->simulationToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
			this->MotionSendText = (gcnew System::Windows::Forms::TextBox());
			this->MotionSendBtn = (gcnew System::Windows::Forms::Button());
			this->groupBox1->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->HeadBar_V))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->HeadBar_H))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->Camera))->BeginInit();
			this->menuStrip1->SuspendLayout();
			this->groupBox2->SuspendLayout();
			this->SuspendLayout();
			// 
			// timer1
			// 
			this->timer1->Enabled = true;
			this->timer1->Interval = 10;
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->HeadBar_V);
			this->groupBox1->Controls->Add(this->HeadBar_H);
			this->groupBox1->Controls->Add(this->Camera);
			this->groupBox1->Location = System::Drawing::Point(10, 30);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(706, 564);
			this->groupBox1->TabIndex = 3;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"Camera Image";
			// 
			// HeadBar_V
			// 
			this->HeadBar_V->Location = System::Drawing::Point(655, 21);
			this->HeadBar_V->Maximum = 1024;
			this->HeadBar_V->Name = L"HeadBar_V";
			this->HeadBar_V->Orientation = System::Windows::Forms::Orientation::Vertical;
			this->HeadBar_V->Size = System::Drawing::Size(45, 480);
			this->HeadBar_V->TabIndex = 3;
			this->HeadBar_V->Value = 512;
			this->HeadBar_V->Scroll += gcnew System::EventHandler(this, &Form1::HeadBar_V_Scroll);
			// 
			// HeadBar_H
			// 
			this->HeadBar_H->Location = System::Drawing::Point(9, 507);
			this->HeadBar_H->Maximum = 1024;
			this->HeadBar_H->Name = L"HeadBar_H";
			this->HeadBar_H->Size = System::Drawing::Size(640, 45);
			this->HeadBar_H->TabIndex = 2;
			this->HeadBar_H->Value = 512;
			this->HeadBar_H->Scroll += gcnew System::EventHandler(this, &Form1::HeadBar_H_Scroll);
			// 
			// Camera
			// 
			this->Camera->Location = System::Drawing::Point(9, 21);
			this->Camera->Name = L"Camera";
			this->Camera->Size = System::Drawing::Size(640, 480);
			this->Camera->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
			this->Camera->TabIndex = 1;
			this->Camera->TabStop = false;
			// 
			// menuStrip1
			// 
			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->aToolStripMenuItem1});
			this->menuStrip1->Location = System::Drawing::Point(0, 0);
			this->menuStrip1->Name = L"menuStrip1";
			this->menuStrip1->Size = System::Drawing::Size(904, 24);
			this->menuStrip1->TabIndex = 4;
			this->menuStrip1->Text = L"menuStrip1";
			// 
			// aToolStripMenuItem1
			// 
			this->aToolStripMenuItem1->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->realToolStripMenuItem, 
				this->simulationToolStripMenuItem});
			this->aToolStripMenuItem1->Name = L"aToolStripMenuItem1";
			this->aToolStripMenuItem1->Size = System::Drawing::Size(55, 20);
			this->aToolStripMenuItem1->Text = L"Mode";
			// 
			// realToolStripMenuItem
			// 
			this->realToolStripMenuItem->Checked = true;
			this->realToolStripMenuItem->CheckState = System::Windows::Forms::CheckState::Checked;
			this->realToolStripMenuItem->Enabled = false;
			this->realToolStripMenuItem->Name = L"realToolStripMenuItem";
			this->realToolStripMenuItem->Size = System::Drawing::Size(175, 22);
			this->realToolStripMenuItem->Text = L"Real Environment";
			this->realToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::realToolStripMenuItem_Click);
			// 
			// simulationToolStripMenuItem
			// 
			this->simulationToolStripMenuItem->Name = L"simulationToolStripMenuItem";
			this->simulationToolStripMenuItem->Size = System::Drawing::Size(175, 22);
			this->simulationToolStripMenuItem->Text = L"Simulation";
			this->simulationToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::simulationToolStripMenuItem_Click);
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->MotionSendBtn);
			this->groupBox2->Controls->Add(this->MotionSendText);
			this->groupBox2->Location = System::Drawing::Point(725, 30);
			this->groupBox2->Name = L"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(167, 55);
			this->groupBox2->TabIndex = 5;
			this->groupBox2->TabStop = false;
			this->groupBox2->Text = L"Motion Assign";
			// 
			// MotionSendText
			// 
			this->MotionSendText->Location = System::Drawing::Point(6, 21);
			this->MotionSendText->Name = L"MotionSendText";
			this->MotionSendText->Size = System::Drawing::Size(67, 22);
			this->MotionSendText->TabIndex = 0;
			this->MotionSendText->Text = L"0";
			// 
			// MotionSendBtn
			// 
			this->MotionSendBtn->Location = System::Drawing::Point(79, 19);
			this->MotionSendBtn->Name = L"MotionSendBtn";
			this->MotionSendBtn->Size = System::Drawing::Size(75, 23);
			this->MotionSendBtn->TabIndex = 1;
			this->MotionSendBtn->Text = L"Send";
			this->MotionSendBtn->UseVisualStyleBackColor = true;
			this->MotionSendBtn->Click += gcnew System::EventHandler(this, &Form1::MotionSendBtn_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(904, 604);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->menuStrip1);
			this->MainMenuStrip = this->menuStrip1;
			this->Name = L"Form1";
			this->Text = L"RoboCup Strategy";
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->HeadBar_V))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->HeadBar_H))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->Camera))->EndInit();
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			this->groupBox2->ResumeLayout(false);
			this->groupBox2->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion

private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
			 
			 //如果是在模擬狀況
			 if (this->simulationToolStripMenuItem->Checked )
			 {
				 //從Share Mem中抓取攝影機影像
				 //delete bmp;

				 System::Drawing::Bitmap^ bmp =  gcnew System::Drawing::Bitmap(CamreaWidth,CamreaHeight,CamreaWidth*3,
					 System::Drawing::Imaging::PixelFormat::Format24bppRgb,
					 System::IntPtr(Mem_Info->Strategy.camImgBuffer));

				 this->Camera->Image = bmp;
			 }
		 }
private: System::Void realToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 
			 this->simulationToolStripMenuItem->Enabled = true;
			 this->realToolStripMenuItem->Enabled = false;
			 this->simulationToolStripMenuItem->Checked = false;
			 this->realToolStripMenuItem->Checked = true;

			 //刪除記憶體共享
			 delete ShareMemClient;
		 }
private: System::Void simulationToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 
			 this->simulationToolStripMenuItem->Enabled = false;
			 this->realToolStripMenuItem->Enabled = true;
			 this->simulationToolStripMenuItem->Checked = true;
			 this->realToolStripMenuItem->Checked = false;

			 //設定記憶體共享 
			 ShareMemClient = new CShareMem();
			 ShareMemClient->server = false;
			 LPCTSTR mapname = "shmmap";
			 ShareMemClient->CreateFileMap( mapname, 0, sizeof(mem_information) );
			 ShareMemClient->MapViewofFile(0);
			 Mem_Info = (mem_information *)ShareMemClient->pMapView;
		 }
private: System::Void HeadBar_V_Scroll(System::Object^  sender, System::EventArgs^  e) {

			 Mem_Info->Strategy.Command.HeadAngle.V = this->HeadBar_V->Value;
		 }
private: System::Void HeadBar_H_Scroll(System::Object^  sender, System::EventArgs^  e) {

			 Mem_Info->Strategy.Command.HeadAngle.H = this->HeadBar_H->Value;
		 }
private: System::Void MotionSendBtn_Click(System::Object^  sender, System::EventArgs^  e) {

			 Mem_Info->Strategy.Command.MotionSend = true;
			 Mem_Info->Strategy.Command.Motion = System::Convert::ToInt32(this->MotionSendText->Text);
		 }
};
}

